package be.donovan.gui.invoice;

import java.awt.Component;
import java.util.ArrayList;
import java.util.Collection;

import javax.swing.AbstractCellEditor;
import javax.swing.CellEditor;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

import be.donovan.gui.helper.components.AbstractController;
import be.donovan.gui.helper.components.AbstractDTOController;
import be.donovan.gui.helper.components.CatalogEditorPanel;
import be.donovan.model.InvoiceItem;
import be.donovan.model.Product;

public class InvoiceController extends AbstractController<InvoiceScreen>{

	private AbstractController invoiceLinesController = new InvoiceLineController();

	@Override
	public void initData() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void initListeners() {
		getView().invoiceLinesPanel.invoicePanel.setController(this.invoiceLinesController);
		try {
			getView().invoiceLinesPanel.invoicePanel.afterPropertiesSet();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	class InvoiceLineController extends AbstractDTOController<InvoiceItem>{
		@Override
		public void initListeners() {
			super.initListeners();
			getView().catalogTable.setDefaultEditor(Product.class, new ProductCellEditor() {
			
			
			});
		}
		class ProductCellEditor extends AbstractCellEditor implements TableCellEditor{
			private static final long serialVersionUID = 1L;
			CatalogEditorPanel catalogEditorPanel = new CatalogEditorPanel(Product.class);
			public Object getCellEditorValue() {
				return new JLabel("test");
			}
			public Component getTableCellEditorComponent(JTable table,
					Object value, boolean isSelected, int row, int column) {
				if(isSelected)
					catalogEditorPanel.start(getView());
				return new JLabel("test");
			}
			
		}
		@Override
		public Class<InvoiceItem> getDtoClass() {
			return InvoiceItem.class;
		}


		@Override
		public Collection<InvoiceItem> readAll() {
			return new ArrayList<InvoiceItem>();
		}

		@Override
		public void saveAll() {
			// TODO Auto-generated method stub
			
		}
		
	}
	

}
